package com.sean.findme.search;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.sean.findme.FmActivityInfo;
import com.sean.findme.FmActivityMgrCtrller;
import com.sean.findme.R;

public class SearchActivityGroup extends ActivityGroup{
	
	LinearLayout container = null;
	SearchActivityManager searchActivityMgr = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.groupactivity);
		
		searchActivityMgr = new SearchActivityManager(this);
		FmActivityMgrCtrller.getInstance(null).registerActivityMgr(getResources().getString(R.string.search_tab), searchActivityMgr);
		
		
		container = (LinearLayout)findViewById(R.id.group_activity_layout);
		container.removeAllViews();
		Intent intent = new Intent(SearchActivityGroup.this,SearchMainActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		
		searchActivityMgr.configFirstActivity(this);
		
		Window window = this.getLocalActivityManager().startActivity("SearchMainActivity", intent);
		View view = window.getDecorView();
		container.addView(view);
		
		LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams();
		params.width = LayoutParams.FILL_PARENT;
		params.height = LayoutParams.FILL_PARENT;
		
		view.setLayoutParams(params);
		
	}

	@Override
	public void onBackPressed() {
		if( searchActivityMgr.getListActivityInfo().size() <= 1)
			super.onBackPressed();
		else
		{
			searchActivityMgr.getListActivityInfo().pop();
			FmActivityInfo info = searchActivityMgr.getListActivityInfo().peek();
			searchActivityMgr.JmpActivity(this.getCurrentActivity().getBaseContext(), info.getFromCls(), info.getActivityGroup(), info.getMap(), false);
		}
	}
	
	

}
